package com.lance.answer.gui.answer.gk.answer.lms.batch;

import com.google.common.base.Strings;
import com.lance.answer.gui.answer.gk.answer.lms.batch.dto.LmsWatchDTO;
import com.lance.answer.gui.answer.gk.answer.lms.batch.task.BatchCreteTopicTask;
import com.lance.answer.gui.answer.gk.answer.lms.batch.task.BatchDoSheHuiShiJianTask;
import com.lance.answer.gui.answer.gk.answer.lms.util.LmsUtil;
import org.apache.commons.io.IOUtils;

import java.io.FileInputStream;
import java.io.InputStream;
import java.util.List;
import java.util.Map;
import java.util.concurrent.LinkedBlockingDeque;

/**
 * 做大作业
 */
public class BatchCreateTopic {


    public static void main(String[] args) throws Exception {


   //     Thread.sleep(1200*60*60*3);
        int sync = 14;

        LinkedBlockingDeque<LmsWatchDTO> watchQueue = new LinkedBlockingDeque<>();

        InputStream inputStream2 = new FileInputStream("libs//lmsTeachers//all3.user");
        List<String> userString = IOUtils.readLines(inputStream2, "utf-8");

        for (String user : userString) {
            String[] strs = user.split(",");
            String userCode = strs[0];
            String pwd = strs[1];

            Map<Long, String> courseMap = LmsUtil.getUserCourseMap(userCode);
            if (null == courseMap) {
                continue;
            }

            for (Long cId : courseMap.keySet()) {
                String subjectName = courseMap.get(cId);
                if (Strings.isNullOrEmpty(subjectName)) {
                    continue;
                }
                if (subjectName.equals("政治经济学")
                ) {

                    LmsWatchDTO lmsWatchDTO = new LmsWatchDTO();
                    lmsWatchDTO.setUsername(userCode);
                    lmsWatchDTO.setPassword(pwd);
                    lmsWatchDTO.setCourseId(cId);
                    lmsWatchDTO.setCourseName(subjectName);
                    watchQueue.add(lmsWatchDTO);
                }
            }




        }

        for (int i = 1; i <= sync; i++) {
            Thread answerThread = new BatchCreteTopicTask("d:\\ynouAutoStudy\\chromedriver.exe", watchQueue);
            //log.info("加载课程ID：{} 名称：{} ", openCourseId,subjectName);
            answerThread.setName("答题线程--" + i);
            answerThread.start();
        }
    }


}
